﻿<?xml version="1.0" encoding="utf-8" ?>
<Feature id="Contacts" name="Contacts Management Feature" >
	<Dependencies>
		<Dependency type="feature">DataScarfFeature.xml</Dependency>
	</Dependencies>
	
	<BusinessRules>

		<BusinessRule name="checkContactOptions" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getContactTypes" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="updateContactType" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="deleteContactType" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getAddressTypes" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="updateAddressType" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="deleteAddressType" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getCountries" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getCountryStates" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="updateAddress" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getCompanyContactTemplate"  security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
    <BusinessRule name="getContactDetail" security="disabled">
      <Option value="$ContactsRemoteTier$">
        <RemoteRule url="$ContactsRemoteTier$" />
        <LocalClass name="Contacts.ContactsBizRules,ScsCore" />
      </Option>
    </BusinessRule>
    <BusinessRule name="getContactDetailFromExtId" security="disabled">
      <Option value="$ContactsRemoteTier$">
        <RemoteRule url="$ContactsRemoteTier$" />
        <LocalClass name="Contacts.ContactsBizRules,ScsCore" />
      </Option>
    </BusinessRule>
    
    <BusinessRule name="getContacts" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="createContact" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="updateContact" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactsRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		
		<BusinessRule name="deleteContact" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactsBizRules,ScsCore" />
			</Option>
		</BusinessRule>
	</BusinessRules>

	<BusinessRules>
		<BusinessRule name="spiderScarfContact" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactScarfingBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="scarfContactConnector" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactScarfingBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="associateAllKnowContacts" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactScarfingBizRules,ScsCore" />
			</Option>
		</BusinessRule>
	</BusinessRules>

	<BusinessRules>
		<BusinessRule name="getContactAddressTemplate" security="disabled">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactDisplayTemplateBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		
		<BusinessRule name="getContactCompanySettingsTemplate" security="disabled" postExtends="getCompanySettingsDisplayTemplate">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactDisplayTemplateBizRules,ScsCore" />
			</Option>
		</BusinessRule>
		<BusinessRule name="getContactCompanySettingsDbFieldNames" security="disabled" postExtends="getCompanySettingsDbFields">
			<Option value="$ContactsRemoteTier$">
				<RemoteRule url="$ContactManagementRemoteTier$" />
				<LocalClass name="Contacts.ContactDisplayTemplateBizRules,ScsCore" />
			</Option>
		</BusinessRule>
	</BusinessRules>
	
	<BusinessObjects>
		<BusinessObject type="ContactType" key="id" >
			<Field name="id" type="Guid" />
			<Field name="name" type="String" />
			<Field name="companyId" type="Guid" />
			<Field name="mapImageName" type="String" />
			<Field name="cacheName" type="String" />
			<Field name="mapImageUrl" type="String" />
		</BusinessObject>

		<BusinessObject type="Contact" key="id">
			<Field name="id" type="Guid" ><NULL/></Field>
			<Field name="extId" type="String" />
			<Field name="lastName" type="String" />
			<Field name="firstName" type="String" />
			<Field name="middleName" type="String" />
			<Field name="phone" type="String" />
			<Field name="mobile" type="String" />
			<Field name="email" type="String" />
			<Field name="isUser" type="Boolean" />
			<Field name="addresses" type="List(Address)" />
			<Field name="type" type="ContactType" />
			<Field name="companyId" type="Guid" />

      <Field name="dateCreated" type="Date"><NULL/></Field>
      <Field name="dateUpdated" type="Date"><NULL/></Field>
      
      <Field name="avitarImage" type="String" />
      <Field name="customTitle" type="String" />
      <Field name="dateOfBirth" type="Date"><NULL/></Field>
      <Field name="gender" type="String">U</Field>
      <Field name="location" type="String" />
      
			<Method name="fullName" language="jscript.NET">
				<![CDATA[
					return self.getItem("firstName") + " " + self.getItem("middleName") + " " + self.getItem("lastName")
				]]>			 
			</Method>			
			<Method name="fileAs" language="jscript.NET">
				<![CDATA[
					return self.getItem("lastName") + ", " + self.getItem("firstName") + " " + self.getItem("middleName")
				]]>			 
			</Method>
			<Method name="defaultLoginName" language="jscript.NET">
				<![CDATA[
					return (self.getItem("firstName") + "." + self.getItem("lastName"))
				]]>
			</Method>
			<Method name="defaultPassword" language="jscript.NET">
				<![CDATA[
					return "password";
				]]>
			</Method>
			<Method name="defaultAddress" language="jscript.NET">
				<![CDATA[
					var l = self.getItem("addresses");
					if(l.numElements > 0)
						return l[0];
						
					return l.insertNew();
				]]>
			</Method>
		</BusinessObject>
		
		<BusinessObject type="AddressType" extends="Article" key="id">
			<Field name="id" type="Guid" ><NULL/></Field>
			<Field name="mapImageName" type="String" />
			<Field name="cacheName" type="String" />
			<Field name="mapImageUrl" type="String" />
			<Field name="currentMapImageName" type="String" />
		</BusinessObject>
		
		<BusinessObject type="Address" key="id" >
			<Field name="id" type="Guid" ><NULL/></Field>
			<Field name="type" type="AddressType" />
			<Field name="contactId" type="Guid"><NULL/></Field>
			<Field name="street1" type="String" />
			<Field name="street2" type="String" />
			<Field name="street3" type="String" />
			<Field name="city" type="String" />
			<Field name="stateProvince" type="String" />
			<Field name="zipCode" type="String" />
			<Field name="country" type="Country" />
			<Field name="longitude" type="String" />
			<Field name="latitude" type="String" />

			<Method name="location" language="jscript.NET"><![CDATA[
				var loc = new StringBuilder();
				if(!Cmn.IsEmpty(self.getItem("street1")))
					loc.Append(self.getItem("street1")).Append(", ");
				if(!Cmn.IsEmpty(self.getItem("city")))
					loc.Append(self.getItem("city")).Append(", ");
				if(!Cmn.IsEmpty(self.getItem("stateProvince")))
					loc.Append(self.getItem("stateProvince")).Append(", ");
				if(!Cmn.IsEmpty(self.getItem("zipCode")))
					loc.Append(self.getItem("zipCode")).Append(", ");
				return(loc.Length > 2)?loc.ToString(0, loc.Length - 2):loc.ToString();
			]]></Method>
		</BusinessObject>
		
		<BusinessObject injects="Company" >
			<Field name="contact" type="Contact" />
		</BusinessObject>
		<BusinessObject injects="User" >
			<Field name="contact" type="Contact" />
		</BusinessObject>
		<BusinessObject injects="CompanySettings">
			<Field name="defaultNewContactCountry" type="String" />
		</BusinessObject>
	</BusinessObjects>

	<BusinessObjects>
		<BusinessObject type="ContactScarfRuntimeInfo" extends="ScarfRuntimeInfo">
			<Field name="totalNewContactsFound" type="Integer" />
			<Field name="totalNewArticlesFound" type="Integer" />
			
			<Field name="uniqueContacts" type="Map" xmlOut="rawElement" />
			<Method name="totalContactsFound" language="jscript.NET" xmlOut="attrib"><![CDATA[
				return self.getItem("uniqueContacts").Count;
			]]></Method>
			<Field name="uniqueConnectors" type="Map" xmlOut="rawElement" />
			<Method name="totalConnectorsFound" language="jscript.NET" xmlOut="attrib"><![CDATA[
				return self.getItem("uniqueConnectors").Count;
			]]></Method>
		</BusinessObject>

		<BusinessObject type="ContactScarfDataPoint" key="fieldName">
			<Field name="fieldName" type="String" />
			<Field name="detailUrl" type="String" />
			<Field name="elementRegex" type="String" />
			<Field name="dataType" type="String">text</Field> <!--Known: image, text -->
			<Field name="imageNameFormat" type="String" />
		</BusinessObject>

		<BusinessObject type="ContactScarfConnector" key="id">
			<Field name="id" type="String" />
			<Field name="bizObjType" type="String" />
			<Field name="sectionRegex" type="String" />
			<Field name="elementRegex" type="String" />
			<Field name="elementDetailsUrl" type="String" />
			<Field name="maxElements" type="Integer" />

			<Field name="baseElementDetailRegex" type="String" />
			<Field name="dataPoints" type="List(ContactScarfDataPoint)" />
			<Field name="elementSegments" type="List(ContactScarfDataPoint)" />
			<Field name="connectors" type="List(ContactScarfConnector)" />
		</BusinessObject>

		<BusinessObject type="ContactScarf" key="id" extends="SiteScarf">
			<Field name="contactDetailsPageUrl" type="String" />
			<Field name="contactType" type="Guid" />
			<Field name="baseContactDetailRegex" type="String" />
			<Field name="runtime" type="ContactScarfRuntimeInfo" />
			<Field name="connectors" type="List(ContactScarfConnector)" />

			<Field name="rootArticleId" type="Guid" />
			<Field name="parentIds" type="Map" />
		</BusinessObject>

		<BusinessObject type="CountryState" key="shortName">
			<Field name="shortName" type="String" />
			<Field name="name" type="String" />
			<Field name="countryCode" type="String" />
		</BusinessObject>
	</BusinessObjects>

	<ApplicationData>
		<Entry name="contactOptions" type="Swaf.Container.FlexiMap" />
		<Entry name="contactOptions.defaultType" type="Swaf.BGuid.Guid">{2F920C1B-A680-4ead-B32E-CEEADBB71757}</Entry>
		<Entry name="contactOptions.types" type="IBizObjList.ContactType">
			<ContactTypes>
				<ContactType id="{3B3A0570-6A88-4704-AD81-4123AF311DD7}" name="Company" />
				<ContactType id="{28B6E3E0-C178-43df-81AC-C837F1AC8696}" name="Customer" />
				<ContactType id="{B396DA83-9864-4742-A18D-F03E7D971E10}" name="Vendor" />
				<ContactType id="{2F920C1B-A680-4ead-B32E-CEEADBB71757}" name="Employee" />
				<ContactType id="{FA074324-09D8-4080-8BD3-BE99A2DD8A83}" name="Department" />
				<ContactType id="{119374C3-839D-4632-BCDB-B9C5ADAFFDBA}" name="Branch" />
			</ContactTypes>
		</Entry>
		

	</ApplicationData>
	   <ApplicationEvents>
		<ApplicationStart>
			<Rule method="checkContactOptions" paramHandling="specifiedOnly">
				<Params/>
			</Rule>
		</ApplicationStart>
	</ApplicationEvents>


	<ClassFactory id="BizProcs">
		<Class type="Contacts.Gui.ContactManagementBP,ScsCore" name="contactBizProc"/>
		<Class type="Contacts.Gui.ContactTypeBizProc,ScsCore" name="contactTypes"/>
		<Class type="Contacts.Gui.AddressTypeBizProc,ScsCore" name="addressTypes"/>
		<Class type="Contacts.Gui.ContactAddressesBizProc,ScsCore" name="contactAddresses"/>
		<Class type="Contacts.Gui.ProfileContactEditBizProc,ScsCore" name="profileContactBizProc"/>
		<Class type="Contacts.Gui.ContactSignUpBP,ScsCore" name="contactSignUpBP"/>		 
	</ClassFactory>
	
</Feature>
